use Untappd;

open (MYFILE, '<data_new1.csv');
open (BEERFILE, '>>beer_ratings_new1.csv');

my $untappd = Untappd->new({
   client_id     => "019FE8B51CDD97BB2B1929768AF736453F9C5A58",
   client_secret => "57AAC4C13BA60D042D7703AB6EE40A547331A5E0",
});

$i = 0;

while ((my $line = <MYFILE>))
{
    my @fields = split " " , $line;

    $id = @fields[0];
    print "$id\n";
    

    if ($i < 91 && $i > 1)
    {
        my $beer = $untappd->beer_info({ bid => "$id" });

        print BEERFILE "$beer->{beer}{bid}, ",
              "$beer->{beer}{beer_abv}, ",
              "$beer->{beer}{beer_name}, $beer->{beer}{brewery}{brewery_name}, ",
              "$beer->{beer}{brewery}{location}{brewery_city}, ",
              "$beer->{beer}{brewery}{location}{brewery_state}, ",
              "$beer->{beer}{beer_style}, ",
              "$beer->{beer}{rating_score}, \n";
    }
    $i = $i+1;
}

close(MYFILE);
close(BEERFILE);
#my $beer = $untappd->beer_info({ bid => "9681" });

#print "$beer->{beer}{beer_name} by $beer->{beer}{brewery}{brewery_name}, ",
#      "in $beer->{beer}{brewery}{location}{brewery_city}, ",
#      "$beer->{beer}{brewery}{location}{brewery_state}, ",
#      "rated $beer->{beer}{rating_score}, \n";